#include <stdlib.h>
#include "Color.h"
#include "ColorConvert.h"

Color* newColor(HSV hsv, int maxValue) {
	Color* color = newColor(maxValue);
	color->setHSV(hsv);
	return color;
}

Color* newColor(RGB rgb, int maxValue) {
	Color* color = newColor(maxValue);
	color->setRGB(rgb);
	return color;
}

Color* newColor(int _maxValue) {
	Color* color;
	color = (Color*) malloc(sizeof(Color));
	color->setMaxValue(_maxValue);
	return color;
}

void Color::setMaxValue(int _maxValue) {
	maxValue = _maxValue;
}

void Color::setRGB(RGB _rgb) {
	colorSpace = RGB_COLOR_SPACE;
	rgb = _rgb;
}

void Color::setHSV(HSV _hsv) {
	colorSpace = HSV_COLOR_SPACE;
	hsv = _hsv;
}

void Color::setYIQ(YIQ _yiq) {
	colorSpace = YIQ_COLOR_SPACE;
	yiq = _yiq;
}

HSV Color::getHSV() {
	if (colorSpace == HSV_COLOR_SPACE) {
		return hsv;
	} else if (colorSpace == RGB_COLOR_SPACE) {
		return RGBtoHSV(rgb, maxValue);
	} else if (colorSpace == YIQ_COLOR_SPACE) {
		RGB rgb = YIQtoRGB(yiq);
		return RGBtoHSV(rgb, maxValue);
	}
}

RGB Color::getRGB() {
	if (colorSpace == HSV_COLOR_SPACE) {
		return HSVtoRGB(hsv, maxValue);
	} else if (colorSpace == RGB_COLOR_SPACE) {
		return rgb;
	} else if (colorSpace == YIQ_COLOR_SPACE) {
		return YIQtoRGB(yiq);
	}
}

